package main

import (
	"log"
	"net/http"
	"url-shortener/internal/config"
	"url-shortener/internal/handler"
	"url-shortener/internal/service"
	"url-shortener/internal/storage"
)

func main() {
	// 加载配置
	cfg := config.Load()

	// 初始化存储
	// redisAddr := "localhost:6379"
	// redisPassword := ""
	// redisDB := 0
	// storage := storage.NewRedisStorage(redisAddr, redisPassword, redisDB)

	storage := storage.NewMemoryStorage()

	// 初始化服务
	service := service.NewService(storage, &service.Config{
		ShortCodeLength: 6,
	})

	// 初始化处理器
	handler := handler.NewHandler(service, cfg.BaseURL)

	// 设置路由
	http.HandleFunc("/shorten", handler.HandleShorten)
	http.HandleFunc("/", handler.HandleRedirect)

	// 启动服务器
	log.Printf("Starting server on port %s", cfg.ServerPort)
	log.Printf("Base URL: %s", cfg.BaseURL)
	log.Fatal(http.ListenAndServe(":"+cfg.ServerPort, nil))
}
